<template>
    <div class="fhsd hw100">
        <div class="fontGjqy">
            <span style="padding: 14px 0 0px 0">防护手段{{TableShow?"":`/${fhsdId?"编辑":"添加"}数据`}}</span>
        </div>
        <div class="redwTable table" v-if="TableShow" style="overflow-y: auto">
            <div class="buttonBox mb20">
                <el-button
                        style="margin-right: 10px"
                        class="btnDefault"
                        @click="fhgcshowGJQYSelect" v-if="activeName=='fhgc'&&!isNopower()"
                >添加数据
                </el-button>
                <el-button class="btnDefault" @click="fhgcDelectSelectRow" v-if="activeName=='fhgc'&&!isNopower()">批量删除</el-button>
                <el-button
                        style="margin-right: 10px"
                        class="btnDefault"
                        @click="showTYCLSelect" v-if="activeName!='fhgc'&&!isNopower()"
                >添加数据
                </el-button>
                <el-button class="btnDefault" @click="DelectSelectRow" v-if="activeName!='fhgc'&&!isNopower()">批量删除</el-button>

            </div>
            <el-tabs v-model="activeName" @tab-click="handleClick" class="xlqkTab">
                <el-tab-pane label="工事防护" name="fhgc" :key="'fhgc'">
                    <el-table
                            :data="fhgcsliceData"
                            border
                            highlight-current-row
                            style="width: 100%"
                            @selection-change="fhgcselectionChange"
                            row-key="fhgcid"
                    >
                        <el-table-column type="selection" width="55" :reserve-selection="true"></el-table-column>
                        <el-table-column prop="gcmc" label="工程名称"></el-table-column>
                        <el-table-column prop="gcbh" label="工程编号"></el-table-column>
                        <!--<el-table-column prop="gclxmc" label="工程类型"></el-table-column>-->
                        <el-table-column prop="jsdd" label="建设地点"></el-table-column>
                        <el-table-column prop="jd" label="经度"></el-table-column>
                        <el-table-column prop="wd" label="纬度"></el-table-column>
                        <el-table-column prop label="操作" width="130">
                            <template slot-scope="scope">
                         <span @click="fhgceditDmt(scope.row)" class="cursor">
                            <img src="../../assets/images/dmtIcon.png" v-if="!isNopower()"/>
                             <span v-if="isNopower()"  class="normalColor mr10 cursor">多媒体</span>
                          </span>
                                <span @click="fhgceditGjqy(scope.row)" class="ml10 mr10 cursor">
                            <img src="../../assets/image/sjlr/编辑_on.png" v-if="!isNopower()"/>
                                    <span v-if="isNopower()"  class="normalColor  cursor">查看</span>
                          </span>
                                <span v-if="!isNopower()"
                                        @click.prevent="fhgcDelectRow(scope.row)"
                                        class="normalColor cursor"
                                >
                            <img src="../../assets/image/sjlr/删除_on.png" alt/>
                          </span>
                            </template>
                        </el-table-column>
                    </el-table>
                </el-tab-pane>
                <el-tab-pane label="伪装设障防护" name="wzszfh" :key="'wzszfh'">
                    <el-table
                            :data="sliceData"
                            border
                            highlight-current-row
                            style="width: 100%"
                            @selection-change="selectionChange"
                            row-key="fhsdid"
                    >
                        <el-table-column type="selection" width="55" :reserve-selection="true"></el-table-column>
                        <el-table-column prop="bt" label="标题"></el-table-column>
                        <!--<el-table-column prop="fhsdlxmc" label="防护手段类型"></el-table-column>-->
                        <el-table-column prop="wjm" label="文件名"></el-table-column>
                        <!--<el-table-column prop="wjlx" label="文件类型"></el-table-column>-->
                        <el-table-column prop="wjljurl" label="文件路径" width="300"></el-table-column>
                        <el-table-column prop="bz" label="备注"></el-table-column>
                        <el-table-column prop label="操作" width="100">
                            <template slot-scope="scope">
                                <span class="cursor normalColor" @click="editTYCL(scope.row)" v-if="isNopower()">查看</span>
                                <span @click="editTYCL(scope.row)" class="cursor" v-if="!isNopower()">
                <img src="../../assets/image/sjlr/编辑_on.png" title="编辑"/>
              </span>
                                <span
                                        @click.prevent="DelectRow2(scope.row)" v-if="!isNopower()"
                                        class="normalColor cursor"
                                >
                <img src="../../assets/image/sjlr/删除_on.png" title="删除"/>
              </span>
                            </template>
                        </el-table-column>
                    </el-table>
                </el-tab-pane>
                <el-tab-pane label="引偏诱爆防护" name="ypybfh" :key="'ypybfh'">
                    <el-table
                            :data="sliceData"
                            border
                            highlight-current-row
                            style="width: 100%"
                            @selection-change="selectionChange"
                            row-key="fhsdid"
                    >
                        <el-table-column type="selection" width="55" :reserve-selection="true"></el-table-column>
                        <el-table-column prop="bt" label="标题"></el-table-column>
                        <!--<el-table-column prop="fhsdlxmc" label="防护手段类型"></el-table-column>-->
                        <el-table-column prop="wjm" label="文件名"></el-table-column>
                        <!--<el-table-column prop="wjlx" label="文件类型"></el-table-column>-->
                        <el-table-column prop="wjljurl" label="文件路径" width="300"></el-table-column>
                        <el-table-column prop="bz" label="备注"></el-table-column>
                        <el-table-column prop label="操作" width="100">
                            <template slot-scope="scope">
                                <span class="cursor normalColor" @click="editTYCL(scope.row)" v-if="isNopower()">查看</span>
                                <span @click="editTYCL(scope.row)" class="cursor" v-if="!isNopower()">
                <img src="../../assets/image/sjlr/编辑_on.png" title="编辑"/>
              </span>
                                <span
                                        @click.prevent="DelectRow2(scope.row)" v-if="!isNopower()"
                                        class="normalColor cursor"
                                >
                <img src="../../assets/image/sjlr/删除_on.png" title="删除"/>
              </span>
                            </template>
                        </el-table-column>
                    </el-table>
                </el-tab-pane>
                <el-tab-pane label="信息防护" name="xxfh" :key="'xxfh'">
                    <el-table
                            :data="sliceData"
                            border
                            highlight-current-row
                            style="width: 100%"
                            @selection-change="selectionChange"
                            row-key="fhsdid"
                    >
                        <el-table-column type="selection" width="55" :reserve-selection="true"></el-table-column>
                        <el-table-column prop="bt" label="标题"></el-table-column>
                        <!--<el-table-column prop="fhsdlxmc" label="防护手段类型"></el-table-column>-->
                        <el-table-column prop="wjm" label="文件名"></el-table-column>
                        <!--<el-table-column prop="wjlx" label="文件类型"></el-table-column>-->
                        <el-table-column prop="wjljurl" label="文件路径" width="300"></el-table-column>
                        <el-table-column prop="bz" label="备注"></el-table-column>
                        <el-table-column prop label="操作" width="100">
                            <template slot-scope="scope">
                                <span class="cursor normalColor" @click="editTYCL(scope.row)" v-if="isNopower()">查看</span>
                                <span @click="editTYCL(scope.row)" class="cursor" v-if="!isNopower()">
                <img src="../../assets/image/sjlr/编辑_on.png" title="编辑"/>
              </span>
                                <span
                                        @click.prevent="DelectRow2(scope.row)" v-if="!isNopower()"
                                        class="normalColor cursor"
                                >
                <img src="../../assets/image/sjlr/删除_on.png" title="删除"/>
              </span>
                            </template>
                        </el-table-column>
                    </el-table>
                </el-tab-pane>
            </el-tabs>

            <div class="page mt20">
                <pages :page="page" @changePage="changePage1" v-if="activeName=='fhgc'"></pages>
                <pages :page="fhgcpage" @changePage="fhgcchangePage" v-else></pages>
            </div>
        </div>
        <div class="gjqyDetailAdd" v-if="!TableShow&&activeName!='fhgc'">
            <el-form ref="form" :model="form" label-width="180px" style="height: 100%">
                <div class=" txsxstyle">
                    <span class="style_title">基本信息</span>.
                    <div class="jbxxStyle_box">
                        <div class="formBox">
                            <el-form-item
                                    v-for="(item, index) in form.jbsxArr"
                                    :label="item.sxmc"
                                    :key="index"
                                    :prop="'jbsxArr.' + index + '.sxvalue'"
                                    :rules="checkRules(item)"
                            >
                                <div class="flexStart">
                                    <el-input
                                            class="noBg border1"
                                            v-show="item.sxlx == 0 || item.sxlx == 4 || item.sxlx == 5"
                                            :style="{width:item.sxzd=='wjljurl'?'400px':'440px'}"
                                            v-model="item.sxvalue"
                                            :disabled="item.sxzd=='wjljurl'"
                                    ></el-input>
                                    <uploadWj @uploadSuccess="uploadPhotoSuccess" :type="'button'"
                                            v-if="item.sxzd=='wjljurl'"></uploadWj>
                                </div>

                                <el-select
                                        class="noBg border1"
                                        style="width: 440px;"
                                        v-model="item.sxvalue"
                                        v-show="item.sxlx == 1"
                                        placeholder="请选择"
                                >
                                    <el-option
                                            v-for="option in item.selectOption"
                                            :key="option.zdID"
                                            :label="option.zdmc"
                                            :value="option.zdID"
                                    ></el-option>
                                </el-select>

                                <el-date-picker
                                        class="noBg border1"
                                        style="width: 440px;"
                                        v-model="item.sxvalue"
                                        v-show="item.sxlx == 2"
                                        type="datetime"
                                        format="yyyy-MM-dd HH:mm:ss"
                                        value-format="timestamp"
                                        placeholder="选择日期"
                                ></el-date-picker>
                            </el-form-item>
                        </div>
                    </div>
                </div>
            </el-form>
            <div class="textRight mt20">
                <el-button v-if="!isNopower()"
                        class="btnDefault"
                        @click="submitTYCLSelect"
                >保存
                </el-button>
                <el-button
                        class="btnDefault"
                        @click="backList"
                >取消
                </el-button>
            </div>
        </div>
        <div class="gjqyDetailAdd" v-if="!TableShow&&activeName=='fhgc'">
            <el-form ref="fhgcform" :model="fhgcform" label-width="180px" style="height: 100%">
                <div class=" txsxstyle">
                    <span class="style_title">基本信息</span>
                    <div class="txsxstyle_box">
                        <div class="formBox">
                            <el-form-item
                                    v-for="(item, index) in fhgcform.jbsxArr"
                                    :label="item.sxmc"
                                    :key="index"
                                    :prop="'jbsxArr.' + index + '.sxvalue'"
                                    :rules="checkRules(item)"
                            >
                                <el-input
                                        class="noBg border1"
                                        v-show="item.sxlx == 0 || item.sxlx == 4 || item.sxlx == 5||item.sxlx == 8||item.sxlx == 9||item.sxlx == 10"
                                        style="width: 440px;"
                                        v-model="item.sxvalue"
                                ></el-input>
                                <el-select
                                        class="noBg border1"
                                        style="width: 440px;"
                                        v-model="item.sxvalue"
                                        v-show="item.sxlx == 1"
                                        placeholder="请选择"
                                >
                                    <el-option
                                            v-for="option in item.selectOption"
                                            :key="option.zdID"
                                            :label="option.zdmc"
                                            :value="option.zdID"
                                    ></el-option>
                                </el-select>

                                <el-date-picker
                                        class="noBg border1"
                                        style="width: 440px;"
                                        v-model="item.sxvalue"
                                        v-show="item.sxlx == 2"
                                        type="datetime"
                                        format="yyyy-MM-dd HH:mm:ss"
                                        value-format="timestamp"
                                        placeholder="选择日期"
                                ></el-date-picker>
                            </el-form-item>
                        </div>
                    </div>
                </div>
            </el-form>
            <div class="textRight mt20">
                <el-button v-if="!isNopower()"
                        class="btnDefault"
                        @click="fhgcsubmitGJQYSelect"
                >保存
                </el-button>
                <el-button
                        class="btnDefault"
                        @click="fhgcbackList"
                >取消
                </el-button>
            </div>
        </div>
        <el-dialog title="工事防护多媒体信息" :visible.sync="fhgcdmtDialog" :close-on-click-modal="false">
            <el-form ref="fhgcform" :model="fhgcform" label-width="120px" class="dialogDmt">
                <el-form-item width="100%"
                              v-for="(item, index) in fhgcform.dmtArr"
                              :label="'图片'+(index+1)"
                              :key="index"
                              :prop="'dmtArr.' + index + '.wjljurl'"
                              :rules="[{ required: true, message: '必填字段', trigger: ['blur','change'] }]"
                >
                    <div class="flexMiddleCenter " style="width:400px">
                        <el-input :disabled="true"
                                  class="noBg border1"
                                  v-model="item.wjljurl"
                        ></el-input>
                        <upload :index="index"
                                @beforeUpload="fhgcbeforeUploadPhoto(index)"
                                @delImgFromList="fhgcdelImgFromList"
                                @uploadSuccess="fhgcuploadPhotoSuccess"
                                :type="'button'"></upload>
                        <i class="el-icon-circle-plus-outline font24 ml10" @click="fhgcaddDmtArr" v-if="index==0"></i>
                        <i class="el-icon-remove-outline font24 ml10" @click="fhgcdeleteDmtArr(index)"
                           v-if="index>0"></i>
                    </div>
                </el-form-item>
            </el-form>
            <div slot="footer"
                 class="dialog-footer">
                <el-button @click="fhgcsaveDmtArr" class="btnDefault">保存</el-button>
                <el-button @click="fhgcdmtDialog=false" class="btnDefault">取消</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
  import pages from "../base/pages";
  import { baseServe } from "../../request/api";
  import uploadWj from "../base/uploadWj";
  import upload from "../base/upload";

  export default {
    name: "fhsd",
    data() {
      return {
        activeName: "fhgc",
        form: {
          jbsxArr: [
            { "sxvalue": "", "sxID": "bt", "sxmc": "标题", "sxlx": "0", "description": null, "sxzd": "bt", "isbt": "0" },
            {
              "sxvalue": "",
              "sxID": "wjm",
              "sxmc": "文件名",
              "sxlx": "0",
              "description": null,
              "sxzd": "wjm",
              "isbt": "1"
            },
            {
              "sxvalue": "",
              "sxID": "wjljurl",
              "sxmc": "文件url",
              "sxlx": "0",
              "description": null,
              "sxzd": "wjljurl",
              "isbt": "1"
            },

            { "sxvalue": "", "sxID": "sxwzqc", "sxmc": "所需物资器材", "sxlx": "0", "description": null, "sxzd": "sxwzqc", "isbt": "0" },
            {
              "sxvalue": "",
              "sxID": "createTime",
              "sxmc": "采集时间",
              "sxlx": "2",
              "description": null,
              "sxzd": "createTime",
              "isbt": "0"
            },
            {
              "sxvalue": "",
              "sxID": "updateTime",
              "sxmc": "更新时间",
              "sxlx": "2",
              "description": null,
              "sxzd": "updateTime",
              "isbt": "0"
            },
            { "sxvalue": "", "sxID": "bz", "sxmc": "备注", "sxlx": "0", "description": null, "sxzd": "bz", "isbt": "0" }
          ]
        },
        TableShow: true,
        page: {
          //总条数
          total: 0,
          //每页条数
          limit: 10,
          //当前页数
          currentPage: 1,
          pageSizes: [5, 10]
        },
        tableData: [],
        sliceData: [],
        selectRowArr: [],
        fileSuffixType: "",
        //防护工程数据  写到人事防护
        fhgcform: {
          jbsxArr: [
            {
              "sxvalue": "",
              "sxID": "gcmc",
              "sxmc": "工程名称",
              "sxlx": "0",
              "description": null,
              "sxzd": "gcmc",
              "isbt": "1"
            },
            {
              "sxvalue": "",
              "sxID": "gcbh",
              "sxmc": "工程编号",
              "sxlx": "0",
              "description": null,
              "sxzd": "gcbh",
              "isbt": "1"
            },
            {
              "sxvalue": "",
              "sxID": "gclx",
              "sxmc": "工程类型",
              "sxlx": "1",
              "selectOption": [{ zdmc: "指挥工程", zdID: "10501" }, { zdmc: "物资储备库", zdID: "10502" }, {
                zdmc: "专业队工程",
                zdID: "10503"
              }, { zdmc: "人员掩蔽工程", zdID: "10504" }, { zdmc: "医疗救护工程", zdID: "10505" }, { zdmc: "其他", zdID: "10506" }],
              "description": null,
              "sxzd": "gclx",
              "isbt": "1"
            },
            {
              "sxvalue": "",
              "sxID": "gcjszt",
              "sxmc": "工程建设状态",
              "sxlx": "1",
              "selectOption": [{ zdmc: "正常", zdID: "10521" }, { zdmc: "在建", zdID: "10522" }, {
                zdmc: "维修",
                zdID: "10523"
              }, { zdmc: "废弃", zdID: "10524" }, { zdmc: "其它", zdID: "10525" }],
              "description": null,
              "sxzd": "gcjszt",
              "isbt": "0"
            },
            { "sxvalue": "", "sxID": "jd", "sxmc": "经度", "sxlx": "9", "description": null, "sxzd": "jd", "isbt": "1" },
            { "sxvalue": "", "sxID": "wd", "sxmc": "纬度", "sxlx": "10", "description": null, "sxzd": "wd", "isbt": "1" },
            {
              "sxvalue": "",
              "sxID": "kgsj",
              "sxmc": "开工时间",
              "sxlx": "2",
              "description": null,
              "sxzd": "kgsj",
              "isbt": "1"
            },
            {
              "sxvalue": "",
              "sxID": "jgsj",
              "sxmc": "竣工时间",
              "sxlx": "2",
              "description": null,
              "sxzd": "jgsj",
              "isbt": "1"
            },
            {
              "sxvalue": "",
              "sxID": "jsdd",
              "sxmc": "建设地点",
              "sxlx": "0",
              "description": null,
              "sxzd": "jsdd",
              "isbt": "0"
            },

            {
              "sxvalue": "",
              "sxID": "jzmj",
              "sxmc": "建筑面积",
              "sxlx": "0",
              "description": null,
              "sxzd": "jzmj",
              "isbt": "0"
            },
            {
              "sxvalue": "",
              "sxID": "symj",
              "sxmc": "使用面积",
              "sxlx": "0",
              "description": null,
              "sxzd": "symj",
              "isbt": "0"
            },
            { "sxvalue": "", "sxID": "yt", "sxmc": "用途", "sxlx": "0", "description": null, "sxzd": "yt", "isbt": "0" },
            {
              "sxvalue": "",
              "sxID": "fzr",
              "sxmc": "负责人",
              "sxlx": "0",
              "description": null,
              "sxzd": "fzr",
              "isbt": "0"
            },
            {
              "sxvalue": "",
              "sxID": "fzrdh",
              "sxmc": "负责人电话",
              "sxlx": "8",
              "description": null,
              "sxzd": "fzrdh",
              "isbt": "0"
            },
            {
              "sxvalue": "",
              "sxID": "krnrs",
              "sxmc": "可容纳人数",
              "sxlx": "0",
              "description": null,
              "sxzd": "krnrs",
              "isbt": "0"
            },
            {
              "sxvalue": "",
              "sxID": "xrnrs",
              "sxmc": "现容纳人数",
              "sxlx": "0",
              "description": null,
              "sxzd": "xrnrs",
              "isbt": "0"
            },
            {
              "sxvalue": "",
              "sxID": "krnrj",
              "sxmc": "可容纳容积",
              "sxlx": "0",
              "description": null,
              "sxzd": "krnrj",
              "isbt": "0"
            },
            {
              "sxvalue": "",
              "sxID": "xrnrj",
              "sxmc": "现容纳容积",
              "sxlx": "0",
              "description": null,
              "sxzd": "xrnrj",
              "isbt": "0"
            },

            { "sxvalue": "", "sxID": "bz", "sxmc": "备注", "sxlx": "0", "description": null, "sxzd": "bz", "isbt": "0" }
          ],
          dmtArr: [
            {
              "dmtid": "",
              "dmtlx": "fhgc",
              "sjid": "",
              "bt": "标题",
              "zz": "",
              "wjm": "文件名",
              "wjlx": "png",
              "wjljurl": ""
            }
          ]
        },
        fhgcTableShow: true,
        fhgcpage: {
          //总条数
          total: 0,
          //每页条数
          limit: 10,
          //当前页数
          currentPage: 1,
          pageSizes: [5, 10]
        },
        fhgctableData: [],
        fhgcsliceData: [],
        fhgcselectRowArr: [],
        fhgcdmtDialog: false,
        wzszTableData: [],
        ypybTableData: [],
        xxfhTableData: []
      };
    },
    mounted() {
      this.getTableByType();
      this.fhgcetTableByType();
    },
    computed: {
      zyjjmbId() {
        return this.$store.state.zyjjmbId;
      },
      fhsdId() {
        return this.$store.state.detailTypeId;
      },
      fhgcId() {
        return this.$store.state.detailTypeId;
      },
    },
    methods: {
      handleClick() {
        this.selectRowArr = [];
        if (this.activeName == "fhgc") {
          this.fhgcetTableByType();
        } else {
          this.getTableByType();
        }
      },
      uploadPhotoSuccess(data) {
        this.form.jbsxArr[2].sxvalue = data.fileDownloadPath;
        // this.$forceUpdate();
        this.fileSuffixType = data.fileSuffixType;
      },
      DelectRow(row) {
        this.$confirm("此操作将批量删除选择项, 是否继续?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        })
          .then(() => {
            baseServe.deletefhsd({ fhsdID: row.fhsdid }).then(() => {
              this.getTableByType();
              this.$message({ type: "success", message: "删除成功" });
              this.selectRowArr=[]
            });
          });
      },
      DelectRow2(row) {
        this.$confirm("此操作将删除该项, 是否继续?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        })
          .then(() => {
            baseServe.deletefhsd({ fhsdID: row.fhsdid }).then(() => {
              this.getTableByType();
              this.$message({ type: "success", message: "删除成功" });
              this.selectRowArr=[]
            });
          });
      },
      DelectSelectRow() {
        let arr = [];
        for (let i = 0; i < this.selectRowArr.length; i++) {
          let target = this.selectRowArr[i].fhsdid;
          arr.push(target);
        }
        if (arr.length) {
          this.DelectRow({ fhsdid: arr.join(",") });
          return;
        }
        this.$message({ type: "warning", message: "请先勾选需要删除的数据" });
      },
      selectionChange(val) {
        this.selectRowArr = val;
      },
      //判断校验规则
      checkRules(item) {
        let arr = [];
        if (item.sxmc == "文件名") {
          arr.push(
            { required: true, message: "必填字段", trigger: ["blur", "change"] },
            { min: 2, max: 30, message: "长度在2-30个字符", trigger: "blur" }
          );
        }
        if (item.sxmc == "防护手段类型") {
          arr.push(
            { required: true, message: "必填字段", trigger: ["blur", "change"] }
          );
        }
        if (item.sxmc == "文件url") {
          arr.push(
            { required: true, message: "必填字段", trigger: ["blur", "change"] }
          );
        }
        if (item.sxmc == "标题") {
          arr.push(
            { validator: this.title, trigger: "blur" }
          );
        }
        if (item.sxmc == "备注") {
          arr.push(
            { validator: this.title, trigger: "blur" }
          );
        }
        if (item.isbt == "1") {
          arr.push({ required: true, message: "必填字段", trigger: "blur" });
        }
        if (item.sxlx == 4) {
          arr.push({ validator: this.checkNum, trigger: "blur" });
        }
        if (item.sxlx == 5) {
          arr.push({ validator: this.checkNumber, trigger: "blur" });
        }
        if (item.sxlx == 8) {
          arr.push({ validator: this.checkMobile, trigger: "blur" });
        }
        if (item.sxlx == 9) {
          arr.push({ validator: this.checkJD, trigger: "blur" });
        }
        if (item.sxlx == 10) {
          arr.push({ validator: this.checkWD, trigger: "blur" });
        }
        return arr;
      },
      getTYCLsxValue() {
        baseServe.searchOneInfo({
          queryType: "fhsd",
          lxId: this.fhsdId
        }).then(res => {
          if (res.data.fhsdModel) {
            let jbsxArrClone = this.form.jbsxArr;
            jbsxArrClone.map((v) => {
              for (let k in res.data.fhsdModel) {
                if (k == v.sxzd) {
                  v.sxvalue = res.data.fhsdModel[k];
                  if (v.sxlx == 2 && v.sxvalue) {
                    v.sxvalue = new Date(v.sxvalue).getTime();
                  }
                }
              }
            });
          }
        });
      },
      //提交
      submitTYCLSelect() {
        this.$refs["form"].validate((valid) => {
          if (valid) {
            let fhsdModel = {};
            this.form.jbsxArr.map(v => {
              if (v.sxzd) {
                fhsdModel[v.sxzd] = v.sxvalue;
                if(v.sxlx==2){
                  params[v.sxzd] =v.sxvalue?new Date(v.sxvalue).getTime() :v.sxvalue
                }
              }
            });
            fhsdModel.wjlx = this.fileSuffixType;
            fhsdModel.zyjjmbid = this.zyjjmbId;
            if (this.activeName == "wzszfh"){
              fhsdModel.fhsdlx = '10102';
          } else if (this.activeName == "ypybfh") {
              fhsdModel.fhsdlx = '10103';
          } else if (this.activeName == "xxfh") {
              fhsdModel.fhsdlx = '10104';
          }

            if (this.fhsdId) {
              fhsdModel.fhsdid = this.fhsdId;
            }
            fhsdModel.rfdwnm=this.$store.state.zyjjmbRfdwnm||null
            baseServe.updatefhsd(fhsdModel).then(() => {
              this.getTableByType();
              this.showTYCLSelect();
              this.TableShow = true;
              this.$message({ type: "success", message: "保存成功" });
            });
          } else {
            this.$message({ type: "warning", message: "请按照规则填写选项" });
            return false;
          }
        });

      },
      //返回
      backList() {
        this.showTYCLSelect();
        this.TableShow = true;
      },
      //新增
      showTYCLSelect() {
        this.$store.state.detailTypeId = "";
        this.TableShow = false;
        if(this.activeName!='xxfh'){
          this.form.jbsxArr = [
            { "sxvalue": "", "sxID": "bt", "sxmc": "标题", "sxlx": "0", "description": null, "sxzd": "bt", "isbt": "0" },
            { "sxvalue": "", "sxID": "wjm", "sxmc": "文件名", "sxlx": "0", "description": null, "sxzd": "wjm", "isbt": "1" },
            {
              "sxvalue": "",
              "sxID": "wjljurl",
              "sxmc": "文件url",
              "sxlx": "0",
              "description": null,
              "sxzd": "wjljurl",
              "isbt": "1"
            },
            { "sxvalue": "", "sxID": "sxwzqc", "sxmc": "所需物资器材", "sxlx": "0", "description": null, "sxzd": "sxwzqc", "isbt": "0" },
            {
              "sxvalue": "",
              "sxID": "createTime",
              "sxmc": "采集时间",
              "sxlx": "2",
              "description": null,
              "sxzd": "createTime",
              "isbt": "0"
            },
            {
              "sxvalue": "",
              "sxID": "updateTime",
              "sxmc": "更新时间",
              "sxlx": "2",
              "description": null,
              "sxzd": "updateTime",
              "isbt": "0"
            },
            { "sxvalue": "", "sxID": "bz", "sxmc": "备注", "sxlx": "0", "description": null, "sxzd": "bz", "isbt": "0" }
          ];
        }else{
          this.form.jbsxArr = [
            { "sxvalue": "", "sxID": "bt", "sxmc": "标题", "sxlx": "0", "description": null, "sxzd": "bt", "isbt": "0" },
            { "sxvalue": "", "sxID": "wjm", "sxmc": "文件名", "sxlx": "0", "description": null, "sxzd": "wjm", "isbt": "1" },
            {
              "sxvalue": "",
              "sxID": "wjljurl",
              "sxmc": "文件url",
              "sxlx": "0",
              "description": null,
              "sxzd": "wjljurl",
              "isbt": "1"
            },
            { "sxvalue": "", "sxID": "xxfhzd", "sxmc": "信息防护重点", "sxlx": "0", "description": null, "sxzd": "xxfhzd", "isbt": "0" },
            { "sxvalue": "", "sxID": "xxfhcs", "sxmc": "信息防护措施", "sxlx": "0", "description": null, "sxzd": "xxfhcs", "isbt": "0" },
            { "sxvalue": "", "sxID": "xxaqbmjy", "sxmc": "信息安全保密教育", "sxlx": "0", "description": null, "sxzd": "xxaqbmjy", "isbt": "0" },
            { "sxvalue": "", "sxID": "sxwzqc", "sxmc": "所需物资器材", "sxlx": "0", "description": null, "sxzd": "sxwzqc", "isbt": "0" },
            {
              "sxvalue": "",
              "sxID": "createTime",
              "sxmc": "采集时间",
              "sxlx": "2",
              "description": null,
              "sxzd": "createTime",
              "isbt": "0"
            },
            {
              "sxvalue": "",
              "sxID": "updateTime",
              "sxmc": "更新时间",
              "sxlx": "2",
              "description": null,
              "sxzd": "updateTime",
              "isbt": "0"
            },
            { "sxvalue": "", "sxID": "bz", "sxmc": "备注", "sxlx": "0", "description": null, "sxzd": "bz", "isbt": "0" }
          ];
        }

      },
      //编辑
      editTYCL(row) {
        this.$store.state.detailTypeId = row.fhsdid;
        if(this.activeName!='xxfh'){
          this.form.jbsxArr = [
            { "sxvalue": "", "sxID": "bt", "sxmc": "标题", "sxlx": "0", "description": null, "sxzd": "bt", "isbt": "0" },
            { "sxvalue": "", "sxID": "wjm", "sxmc": "文件名", "sxlx": "0", "description": null, "sxzd": "wjm", "isbt": "1" },
            {
              "sxvalue": "",
              "sxID": "wjljurl",
              "sxmc": "文件url",
              "sxlx": "0",
              "description": null,
              "sxzd": "wjljurl",
              "isbt": "1"
            },
            { "sxvalue": "", "sxID": "sxwzqc", "sxmc": "所需物资器材", "sxlx": "0", "description": null, "sxzd": "sxwzqc", "isbt": "0" },
            {
              "sxvalue": "",
              "sxID": "createTime",
              "sxmc": "采集时间",
              "sxlx": "2",
              "description": null,
              "sxzd": "createTime",
              "isbt": "0"
            },
            {
              "sxvalue": "",
              "sxID": "updateTime",
              "sxmc": "更新时间",
              "sxlx": "2",
              "description": null,
              "sxzd": "updateTime",
              "isbt": "0"
            },
            { "sxvalue": "", "sxID": "bz", "sxmc": "备注", "sxlx": "0", "description": null, "sxzd": "bz", "isbt": "0" }
          ];
        }else{
          this.form.jbsxArr = [
            { "sxvalue": "", "sxID": "bt", "sxmc": "标题", "sxlx": "0", "description": null, "sxzd": "bt", "isbt": "0" },
            { "sxvalue": "", "sxID": "wjm", "sxmc": "文件名", "sxlx": "0", "description": null, "sxzd": "wjm", "isbt": "1" },
            {
              "sxvalue": "",
              "sxID": "wjljurl",
              "sxmc": "文件url",
              "sxlx": "0",
              "description": null,
              "sxzd": "wjljurl",
              "isbt": "1"
            },
            { "sxvalue": "", "sxID": "xxfhzd", "sxmc": "信息防护重点", "sxlx": "0", "description": null, "sxzd": "xxfhzd", "isbt": "0" },
            { "sxvalue": "", "sxID": "xxfhcs", "sxmc": "信息防护措施", "sxlx": "0", "description": null, "sxzd": "xxfhcs", "isbt": "0" },
            { "sxvalue": "", "sxID": "xxaqbmjy", "sxmc": "信息安全保密教育", "sxlx": "0", "description": null, "sxzd": "xxaqbmjy", "isbt": "0" },
            { "sxvalue": "", "sxID": "sxwzqc", "sxmc": "所需物资器材", "sxlx": "0", "description": null, "sxzd": "sxwzqc", "isbt": "0" },
            {
              "sxvalue": "",
              "sxID": "createTime",
              "sxmc": "采集时间",
              "sxlx": "2",
              "description": null,
              "sxzd": "createTime",
              "isbt": "0"
            },
            {
              "sxvalue": "",
              "sxID": "updateTime",
              "sxmc": "更新时间",
              "sxlx": "2",
              "description": null,
              "sxzd": "updateTime",
              "isbt": "0"
            },
            { "sxvalue": "", "sxID": "bz", "sxmc": "备注", "sxlx": "0", "description": null, "sxzd": "bz", "isbt": "0" }
          ];
        }
        if (this.fhsdId) {
          this.TableShow = false;
          this.getTYCLsxValue();
        }
      },
      //获取表格
      getTableByType() {
        baseServe
          .getGjqyTable({
            queryType: "fhsd",
            zyjjmbId: this.zyjjmbId
          })
          .then(res => {
            if (res.data.fhsdInfos) {
              this.tableData = res.data.fhsdInfos;
              this.page.total = this.tableData.length;
              this.page.currentPage = 1;
              this.pages();
            }
          });
      },
      //前台分页
      pages() {
        this.page.total = this.tableData.length;
        if (!this.page.total % this.page.limit) {
          this.page.currentPage = this.page.currentPage - 1;
        }
        let begin = (this.page.currentPage - 1) * this.page.limit;
        let end = this.page.currentPage * this.page.limit;
        this.wzszTableData = [];
        this.ypybTableData = [];
        this.xxfhTableData = [];
        this.tableData.map(v => {
          if (v.fhsdlx == "10102") {
            this.wzszTableData.push(v);
          }
          if (v.fhsdlx == "10103") {
            this.ypybTableData.push(v);
          }
          if (v.fhsdlx == "10104") {
            this.xxfhTableData.push(v);
          }
        });
        if (this.activeName == "wzszfh") {
          this.sliceData = this.wzszTableData.slice(begin, end);
        } else if (this.activeName == "ypybfh") {
          this.sliceData = this.ypybTableData.slice(begin, end);
        } else if (this.activeName == "xxfh") {
          this.sliceData = this.xxfhTableData.slice(begin, end);
        }
      },
      changePage1(data) {
        this.page = data;
        this.pages();
      },
      //fhgcfhgc
      fhgcsaveDmtArr() {
        this.$refs["fhgcform"].validate((valid) => {
          if (valid) {
            let dmtModels = this.fhgcform.dmtArr;
            dmtModels.map(v => {
              v.sjid = this.fhgcId;
            });
            baseServe.updatedmt({ dmtModels: dmtModels }).then(() => {
              this.getTableByType();
              this.TableShow = true;
              this.fhgcdmtDialog = false;
              this.$message({ type: "success", message: "保存成功" });
            });
          } else {
            this.$message({ type: "warning", message: "请按照规则填写选项" });
            return false;
          }
        });
      },
      fhgcaddDmtArr() {
        this.fhgcform.dmtArr.push({
          "dmtid": "",
          "dmtlx": "fhgc",
          "sjid": "",
          "bt": "标题",
          "zz": "",
          "wjm": "文件名",
          "wjlx": "png",
          "wjljurl": ""
        });
      },
      fhgcdeleteDmtArr(index) {
        this.fhgcform.dmtArr.splice(index, 1);
      },
      fhgcbeforeUploadPhoto(index) {
        this.photoIndex = index;
      },
      fhgcuploadPhotoSuccess(data) {
        this.fhgcform.dmtArr[this.photoIndex].wjljurl = data.fileDownloadPath;
      },
      fhgcdelImgFromList(index) {
        this.photoIndex = index;
        this.fhgcform.dmtArr[this.photoIndex].wjljurl = "";
      },
      fhgceditDmt(row) {
        baseServe.cxdmtByType({
          dmtLx: "fhgc",
          sjID: row.fhgcid
        }).then(res => {
          this.fhgcform.dmtArr =  [
            {
              "dmtid": "",
              "dmtlx": "fhgc",
              "sjid": "",
              "bt": "标题",
              "zz": "",
              "wjm": "文件名",
              "wjlx": "png",
              "wjljurl": ""
            }
          ]
          if (res.data.dmtModels && res.data.dmtModels.length > 0) {
            this.fhgcform.dmtArr = res.data.dmtModels;
          }
          this.$store.state.detailTypeId = row.fhgcid;
          this.fhgcdmtDialog = true;
        });
      },
      fhgcDelectRow(row) {
        this.$confirm("此操作将删除该项, 是否继续?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        })
          .then(() => {
            baseServe.deletefhgc({ fhgcID: row.fhgcid }).then(() => {
              this.fhgcetTableByType();
              this.$message({ type: "success", message: "删除成功" });
            });
          });
      },
      fhgcDelectSelectRow() {
        let arr = [];
        for (let i = 0; i < this.selectRowArr.length; i++) {
          let target = this.selectRowArr[i].fhgcid;
          arr.push(target);
        }
        if (arr.length == 0) {
          this.$message({ type: "warning", message: "请先勾选需要删除的数据" });
          return;
        }
        this.$confirm("此操作将批量删除选择项, 是否继续?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        })
          .then(() => {
            baseServe.deletefhgc({ fhgcID: arr.join(",") }).then(() => {
              this.fhgcetTableByType();
              this.$message({ type: "success", message: "删除成功" });
              this.selectRowArr=[]
            });
          });
      },
      fhgcselectionChange(val) {
        this.selectRowArr = val;
      },
      fhgcgetGjqysxValue() {
        baseServe.searchOneInfo({
          queryType: "fhgc",
          lxId: this.fhgcId
        }).then(res => {
          if (res.data.fhgcModel) {
            let jbsxArrClone = this.fhgcform.jbsxArr;
            jbsxArrClone.map((v) => {
              for (let k in res.data.fhgcModel) {
                if (k == v.sxzd) {
                  v.sxvalue = res.data.fhgcModel[k];
                  if (v.sxlx == 2 && v.sxvalue) {
                    v.sxvalue = new Date(v.sxvalue).getTime();
                  }
                }
              }
            });
          }
        });
      },
      //提交
      fhgcsubmitGJQYSelect() {
        this.$refs["fhgcform"].validate((valid) => {
          if (valid) {
            let params = {};
            this.fhgcform.jbsxArr.map(v => {
              if (v.sxzd) {
                params[v.sxzd] = v.sxvalue;
              }
            });
            params.zyjjmbid = this.zyjjmbId;
            if (this.fhgcId) {
              params.fhgcid = this.fhgcId;
            }
            baseServe.updatefhgc(params).then(() => {
              this.fhgcetTableByType();
              this.fhgcshowGJQYSelect();
              this.TableShow = true;
              this.$message({ type: "success", message: "保存成功" });
            });
          } else {
            this.$message({ type: "warning", message: "请按照规则填写选项" });
            return false;
          }
        });

      },
      //返回
      fhgcbackList() {
        this.fhgcshowGJQYSelect();
        this.TableShow = true;
      },
      //新增
      fhgcshowGJQYSelect() {
        this.$store.state.detailTypeId = "";
        this.fhgcform.jbsxArr = [
          {
            "sxvalue": "",
            "sxID": "gcmc",
            "sxmc": "工程名称",
            "sxlx": "0",
            "description": null,
            "sxzd": "gcmc",
            "isbt": "1"
          },
          {
            "sxvalue": "",
            "sxID": "gcbh",
            "sxmc": "工程编号",
            "sxlx": "0",
            "description": null,
            "sxzd": "gcbh",
            "isbt": "1"
          },
          {
            "sxvalue": "",
            "sxID": "gclx",
            "sxmc": "工程类型",
            "sxlx": "1",
            "selectOption": [{ zdmc: "指挥工程", zdID: "10501" }, { zdmc: "物资储备库", zdID: "10502" }, {
              zdmc: "专业队工程",
              zdID: "10503"
            }, { zdmc: "人员掩蔽工程", zdID: "10504" }, { zdmc: "医疗救护工程", zdID: "10505" }, { zdmc: "其他", zdID: "10506" }],
            "description": null,
            "sxzd": "gclx",
            "isbt": "1"
          },
          {
            "sxvalue": "",
            "sxID": "gcjszt",
            "sxmc": "工程建设状态",
            "sxlx": "1",
            "selectOption": [{ zdmc: "正常", zdID: "10521" }, { zdmc: "在建", zdID: "10522" }, {
              zdmc: "维修",
              zdID: "10523"
            }, { zdmc: "废弃", zdID: "10524" }, { zdmc: "其它", zdID: "10525" }],
            "description": null,
            "sxzd": "gcjszt",
            "isbt": "0"
          },
          { "sxvalue": "", "sxID": "jd", "sxmc": "经度", "sxlx": "9", "description": null, "sxzd": "jd", "isbt": "1" },
          { "sxvalue": "", "sxID": "wd", "sxmc": "纬度", "sxlx": "10", "description": null, "sxzd": "wd", "isbt": "1" },
          {
            "sxvalue": "",
            "sxID": "kgsj",
            "sxmc": "开工时间",
            "sxlx": "2",
            "description": null,
            "sxzd": "kgsj",
            "isbt": "1"
          },
          {
            "sxvalue": "",
            "sxID": "jgsj",
            "sxmc": "竣工时间",
            "sxlx": "2",
            "description": null,
            "sxzd": "jgsj",
            "isbt": "1"
          },
          {
            "sxvalue": "",
            "sxID": "jzmj",
            "sxmc": "建筑面积",
            "sxlx": "0",
            "description": null,
            "sxzd": "jzmj",
            "isbt": "0"
          },
          {
            "sxvalue": "",
            "sxID": "symj",
            "sxmc": "使用面积",
            "sxlx": "0",
            "description": null,
            "sxzd": "symj",
            "isbt": "0"
          },
          { "sxvalue": "", "sxID": "yt", "sxmc": "用途", "sxlx": "0", "description": null, "sxzd": "yt", "isbt": "0" },
          {
            "sxvalue": "",
            "sxID": "fzr",
            "sxmc": "负责人",
            "sxlx": "0",
            "description": null,
            "sxzd": "fzr",
            "isbt": "0"
          },
          {
            "sxvalue": "",
            "sxID": "fzrdh",
            "sxmc": "负责人电话",
            "sxlx": "8",
            "description": null,
            "sxzd": "fzrdh",
            "isbt": "0"
          },
          {
            "sxvalue": "",
            "sxID": "jsdd",
            "sxmc": "建设地点",
            "sxlx": "0",
            "description": null,
            "sxzd": "jsdd",
            "isbt": "0"
          },
          {
            "sxvalue": "",
            "sxID": "krnrs",
            "sxmc": "可容纳人数",
            "sxlx": "0",
            "description": null,
            "sxzd": "krnrs",
            "isbt": "0"
          },
          {
            "sxvalue": "",
            "sxID": "xrnrs",
            "sxmc": "现容纳人数",
            "sxlx": "0",
            "description": null,
            "sxzd": "xrnrs",
            "isbt": "0"
          },
          {
            "sxvalue": "",
            "sxID": "krnrj",
            "sxmc": "可容纳容积",
            "sxlx": "0",
            "description": null,
            "sxzd": "krnrj",
            "isbt": "0"
          },
          {
            "sxvalue": "",
            "sxID": "xrnrj",
            "sxmc": "现容纳容积",
            "sxlx": "0",
            "description": null,
            "sxzd": "xrnrj",
            "isbt": "0"
          },

          { "sxvalue": "", "sxID": "bz", "sxmc": "备注", "sxlx": "0", "description": null, "sxzd": "bz", "isbt": "0" }
        ],
          this.TableShow = false;

      },
      //编辑
      fhgceditGjqy(row) {
        this.$store.state.detailTypeId = row.fhgcid;
        if (this.fhgcId) {
          this.TableShow = false;
          this.fhgcgetGjqysxValue();

        }
      },
      //获取表格
      fhgcetTableByType() {
        baseServe
          .getGjqyTable({
            queryType: "fhgc",
            zyjjmbId: this.zyjjmbId
          })
          .then(res => {
            if (res.data.fhgcInfos) {
              this.fhgctableData = res.data.fhgcInfos;
              this.fhgcpage.total = this.fhgctableData.length;
              this.fhgcpage.currentPage = 1;
              this.fhgcpages();
            }
          });
      },
      //前台分页
      fhgcpages() {
        this.fhgcpage.total = this.fhgctableData.length;
        if (!this.fhgcpage.total % this.fhgcpage.limit) {
          this.fhgcpage.currentPage = this.fhgcpage.currentPage - 1;
        }
        let begin = (this.fhgcpage.currentPage - 1) * this.fhgcpage.limit;
        let end = this.fhgcpage.currentPage * this.fhgcpage.limit;
        this.fhgcsliceData = this.fhgctableData.slice(begin, end);
      },
      fhgcchangePage(data) {
        this.fhgcpage = data;
        this.fhgcpages();
      }
    },
    components: {
      pages,
      upload,
      uploadWj
    }
  };
</script>

<style lang="less" scoped>
    @import "../../assets/css/global.css";

    .fhsd {
        .fontGjqy {
            height: 40px;
            width: 100%;
            font-family: "Microsoft Yahei-Bold";
            color: #00ffff;
            font-size: 18px;
            display: flex;
            margin-bottom: 15px;
            position: relative;
            .el-button {
                position: absolute;
                right: 40px;
                top: 10px;
            }
        }
        .gjqyDetailAdd{
            width: 100%;
            height: calc(100% - 100px) !important;
            .jbxxStyle , .txsxstyle {
                height: 100% !important;
            }
        }
        .redwTable  {
            width: 100%;
            height: calc(100% - 150px) !important;
            overflow: hidden;
        }
    }
</style>
